//iframe自适应
$(window).on('resize', function() {
    var $content = $('.content');
    $content.height($(window).height() - 200);
    $content.find('iframe').each(function() {
        $(this).height($content.height());
    });
}).resize();

TgfMenu.menu({
    url:'jdata/jmenu.json',
    type:'get'
})

var vm = new Vue({
    el:'#tgfapi',
    data:{
        sysuser:{
            username: 'zzj',
        },
        main: 'main.html',
        navTitle:'欢迎页',
        menuList:[]
    },
    methods: {
        getMenuList: function () {
            // $.get('jdata/jmenu.json',{},function (res) {
            //     this.menuList = res.data;
            //     console.log(menuList);
            // })
        }
    },
    created: function() {
        this.getMenuList();
    },
    updated: function(){
        //路由
        // var router = new Router();
        // routerList(router, vm.menuList);
        // router.start();
    }
});

function routerList(router, menuList){
    for(var key in menuList){
        var menu = menuList[key];
        if(menu.type == 0){
            routerList(router, menu.list);
        }else if(menu.type == 1){
            if(menu.url == 'druid/sql.html'){
                menu.url = baseURL + 'druid/sql.html';
            }
            router.add('#'+ menu.url, function() {
                var url = window.location.hash;

                //替换iframe的url
                vm.main = url.replace('#', '');

                //导航菜单展开
                $(".treeview-menu li").removeClass("active");
                $(".sidebar-menu li").removeClass("active");
                $("a[href='"+url+"']").parents("li").addClass("active");

                vm.navTitle = $("a[href='"+url+"']").text();
            });
        }
    }
    console.log("打印hashlist");
    console.log(router.hashList);
}